package com.usf.jprovider.main;

import java.util.Date;
import java.util.logging.Level;

import com.usf.jprovider.factory.JFactory;
import com.usf.jprovider.object.env.Environment;
import com.usf.jprovider.schema.model.jconfiguration.JConfiguration;
import com.usf.jprovider.schema.model.jmodel.JModel;

public final class Main {
	
	public Main() {
		facture();
	}
	public void facture() {
		full("Test/Facture/application.xml", 
				"Test/Facture/facture_model.xml",
				"Test/Facture/facture.xml");
	}
//	public void ot() {
//		full("Test/PIDI/application.xml", 
//				"Test/PIDI/OT_Cloture_model.xml",
//				"Test/PIDI/OT_Cloture.xml");
//	}
	public void full(String confPath, String modelPath, String file){
		Long value = new Date().getTime();
		Environment env = null;
		try {
			JModel model = JFactory.loadJModel(modelPath);
			JConfiguration conf = JFactory.loadConfiguration(confPath);
			env = Environment.newEnvironment(conf);
			JFactory.createAndInject(model, env, file);
			System.out.println(JFactory.check(file, model, env));
			System.out.println("injection in " + (new Date().getTime() - value) + "ms");
		} catch (Exception e) {
			env.getLogger().log(Level.SEVERE, e.getMessage(), e);
			System.err.println("Error ! see logfile");
		}
	}	

	public static void main(String[] args) {
		new Main();
	}
}